package practice.thread.talk.server;

import java.util.List;

public class CleanDeadConnect extends Thread {
	private static Object lock = new Object();

	public CleanDeadConnect() {
	}

	public void run() {
		while (true) {
			try {
				Thread.sleep(2600);
			} catch (InterruptedException e) {
				;
			}

			synchronized (lock) {
				List<ClientThread> clients = AppContext.getInstance()
						.getCloneClients();
				for (ClientThread cThread : clients) {
					if (!cThread.isAlive()) {
						String m = cThread.getClientAddress() + ",:has quit"
								+ AppContext.getInstance().getConnectNumber();
						AppContext.getInstance().pushMessage(m);
						AppContext.getInstance().removeClient(cThread);
					} 
				}
				System.out.println("total number:"
						+ AppContext.getInstance().getConnectNumber());
			}
		}
	}
}
